package patrol.mobile.com.mobilepatrol.utils;

public final class IEUUID {

	private final int unique;

	private long extendTime;

	private static String address;

	private static int hostUnique = (new Object()).hashCode();

	private static Object mutex = new Object();

	private static long lastTime = System.currentTimeMillis();//NOPMD

	private final static long DELAY = 1L;

	private static long postfix = 0;//NOPMD

	public IEUUID() {

		synchronized (mutex) {
			long time = System.currentTimeMillis();
			if (time < lastTime + DELAY) {
				postfix++;
				extendTime = time * 1000 + postfix;
			} else {
				lastTime = time;
				extendTime = time;
				postfix = 0;
			}

			unique = hostUnique;
		}
	}

	public String toString() {
		return Integer.toString(unique, 16) + "-"
				+ Long.toString(extendTime, 16) + "-" + address;
	}
}